package com.tnl.app.dao;

import com.tnl.app.entity.Dictionary;
import com.tnl.base.BaseDAO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author: Jerry
 * @date: 2021/1/18
 */
@Repository
public class DictionaryDAO {

    final String GET_BT_TYPE_AND_VALUE = "select * from sys_dict where type=? and value=?";

    final String LIST_BT_TYPE_AND_VALUE = "select * from sys_dict where type=? and value in";

    public Dictionary getByTypeAndValue(String type, String value){
        return BaseDAO.queryForObject(Dictionary.class, GET_BT_TYPE_AND_VALUE, type, value);
    }

    public List<Dictionary> listByTypeAndValue(String type, List<String> values){
        StringBuilder stringBuilder = new StringBuilder(LIST_BT_TYPE_AND_VALUE);
        stringBuilder.append("(");
        for (String key : values){
            stringBuilder.append(key).append(",");
        }
        stringBuilder.deleteCharAt(stringBuilder.length()-1);
        stringBuilder.append(")");
        return BaseDAO.queryForList(Dictionary.class, stringBuilder.toString(), type);
    }
}
